package com.ai.wxy.spring.auth.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;
import java.util.stream.Collectors;

/**
 * Jwt User DTO
 *
 * @author 石头
 * @Date 2019/10/30
 * @Version 1.0
 **/
@Data
@AllArgsConstructor
public class JwtUserDTO implements UserDetails {
    private final Long id;
    private final String username;
    private final String password;
    private final Collection<GrantedAuthority> authorities;
    private final boolean enabled;
    private final boolean accountNonLocked;
    private final Date lastPasswordResetDate;
    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    public Collection getRoles() {
        return authorities.stream().map(GrantedAuthority::getAuthority).collect(Collectors.toSet());
    }
}
